<!DOCTYPE html >
<html>
<head>
    <link rel="stylesheet" href="demos.css" type="text/css" media="screen" />
    
    <script src="../libraries/RGraph.common.core.js" ></script>
    <script src="../libraries/RGraph.common.dynamic.js" ></script>
    <script src="../libraries/RGraph.common.tooltips.js" ></script>
    <script src="../libraries/RGraph.drawing.xaxis.js" ></script>
    <script src="../libraries/RGraph.drawing.yaxis.js" ></script>
    <script src="../libraries/RGraph.drawing.rect.js" ></script>
    
    <title>RGraph demo: A Bar chart made with the Drawing API objects</title>
    
    <meta name="robots" content="noindex,nofollow" />
    <meta name="description" content="A Bar chart that is made up from drawing API objects" />
    
</head>
<body>

    <!-- Share buttons -->
    <p style="float: right">
        <script>
            document.write('<a href="" target="_blank" onclick="window.open(\'https://www.facebook.com/sharer/sharer.php?u=http://www.rgraph.net' + location.pathname + '\', null, \'top=50,left=50,width=600,height=368\'); return false"><img src="../images/facebook-large.png" width="200" height="43" alt="Share on Facebook" border="0" title="Visit the RGraph Facebook page" id="facebook_link" /></a>&nbsp;');
            document.write('<a href="https://twitter.com/_rgraph" target="_blank" onclick="window.open(\'https://twitter.com/intent/tweet?text=Check%20out%20this%20demo%20of%20RGraph:%202D/3D%20JavaScript%20charts%20-%20Free%20and%20Open%20Source%20http://www.rgraph.net' + location.pathname + '\', null, \'top=50,left=50,width=700,height=400\'); return false"><img src="../images/twitter-large.png" width="200" height="43" alt="Share on Twitter" border="0" title="Mention RGraph on Twitter" id="twitter_link" /></a>');
        </script>
    </p>


    <h1>A Bar chart made with the Drawing API objects</h1>
    
    <p>
        This is a demo of the Drawing API objects being used to make a bar chart all by themselves (without the actual Bar chart).
    </p>

    <canvas id="cvs" width="600" height="250">[No canvas support]</canvas>
    
    <script>
        window.onload = function ()
        {
            var data = [100,80,60,40,20];
            var labels = ['Fred','Barney','Wilma','Betty','Dino'];
            var hmargin = 5;
            var max = 100;
    
            var xaxis = new RGraph.Drawing.XAxis({
                id: 'cvs',
                y: 225,
                options: {
                    labels: labels,
                    gutterLeft: 50,
                    tooltips: ['The X axis shows Flintstones characters'],
                    textAccessible: true,
                    textAccessiblePointerevents: false
                }
            }).draw()
    
            var yaxis = new RGraph.Drawing.YAxis({
                id: 'cvs',
                x: 50,
                options: {
                    max: max,
                    gutterBottom: 25,
                    noendtickBottom: true,
                    noyaxis: true,
                    tooltips: ['The Y axis shows a scale of how much the characters did<br /> something - at some point'],
                    textAccessible: true,
                    textAccessiblePointerevents: false
                }
            }).draw()
        
            for (var i=0; i<data.length; ++i) {
    
                var width = ((600-50-25) / data.length) - (hmargin * 2);
                var height = (data[i] / max) * (xaxis.canvas.height - 25 - 25);
                var x = 50 + (((600-50-25) / data.length) * i) + hmargin;
                var y = 250 - 25 - height;
            
                var rect = new RGraph.Drawing.Rect({
                    id: 'cvs',
                    x: x,
                    y: y,
                    width: width,
                    height: height,
                    options: {
                        tooltips: [labels[i]],
                        highlightStroke: 'rgba(0,0,0,0)'
                    }
                }).draw()
            }
            
            RGraph.redraw();
        };
    </script>
    
    <p>
        <b>Is it quicker than using the standard Bar chart?</b><br />
        No.
    </p>
    
    <p>
        <b>Is it easier to implement than the standard Bar chart?</b><br />
        No.
    </p>
    
    <p>
        <b>Is it easier to maintain than the standard Bar chart?</b><br />
        No.
    </p>
    
    <p>
        <b>Does it encompass all of the features of the standard Bar chart?</b><br />
        No.
    </p>
    
    <p>
        <b>So why?</b><br />
        It's just an example of three of the drawing API objects - the XAxis, the Yaxis and the Rect. If what you want is a Bar
        chart - use the RGraph Bar chart.
    </p>







    <p></p>

    This goes in the documents header:
    <pre class="code">
&lt;script src="RGraph.common.core.js"&gt;&lt;/script&gt;
&lt;script src="RGraph.common.dynamic.js"&gt;&lt;/script&gt;
&lt;script src="RGraph.common.tooltips.js"&gt;&lt;/script&gt;
&lt;script src="RGraph.drawing.xaxis.js"&gt;&lt;/script&gt;
&lt;script src="RGraph.drawing.yaxis.js"&gt;&lt;/script&gt;
&lt;script src="RGraph.bar.js"&gt;&lt;/script&gt;
</pre>
    
    Put this where you want the chart to show up:
    <pre class="code">
&lt;canvas id="cvs" width="600" height="250"&gt;
    [No canvas support]
&lt;/canvas&gt;
</pre>

    This is the code that generates the chart:
    <pre class="code">
&lt;script&gt;
    window.onload = function ()
    {
        var data = [100,80,60,40,20];
        var labels = ['Fred','Barney','Wilma','Betty','Dino'];
        var hmargin = 5;
        var max = 100;

        var xaxis = new RGraph.Drawing.XAxis({
            id: 'cvs',
            y: 225,
            options: {
                labels: labels,
                gutterLeft: 50,
                tooltips: ['The X axis shows Flintstones characters'],
                textAccessible: true,
                textAccessiblePointerevents: false
            }
        }).draw()

        var yaxis = new RGraph.Drawing.YAxis({
            id: 'cvs',
            x: 50,
            options: {
                max: max,
                noendtickBottom: true,
                scaleZerostart: false,
                noyaxis: true,
                tooltips: ['The Y axis shows a scale of how much the characters did<br /> something - at some point'],
                textAccessible: true,
                textAccessiblePointerevents: false
            }
        }).draw()
    
        for (var i=0; i&lt;data.length; ++i) {

            var width = ((600-50-25) / data.length) - (hmargin * 2);
            var height = (data[i] / max) * (xaxis.canvas.height - 25 - 25);
            var x = 50 + (((600-50-25) / data.length) * i) + hmargin;
            var y = 250 - 25 - height;
        
            var rect = new RGraph.Drawing.Rect({
                id: 'cvs',
                x: x,
                y: y,
                width: width,
                height: height,
                options: {
                    tooltips: [labels[i]],
                    highlightStroke: 'rgba(0,0,0,0)'
                }
            }).draw()
        }
        
        RGraph.redraw();
    };
&lt;/script&gt;
</pre>


    

    <p>
        <a href="./">&laquo; Back</a>
    </p>

</body>
</html>